package com.aifast.system.sys.controller;


import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.Controller;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.sys.entity.SysDict;
import com.aifast.system.sys.service.SysDictService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 字典类别 前端控制器
 * </p>
 *
 * @author fujian
 * @since 2021-12-29
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/sysDict")
public class SysDictController extends Controller {

    private final SysDictService sysDictService;

//    @SaCheckPermission("dict:list")
    @GetMapping("list")
    public LayuiDataTable getCatalogs() {
        return sysDictService.getDicts(get("search"), getPage(1, 1000));
    }

    @AiIdempotent
//    @SaCheckPermission("dict:addOrUpdate")
    @PostMapping("add")
    public R addCatalog(SysDict sysDict) {
        return sysDictService.insertOrUpdate(sysDict) ? OK() : ERROR();
    }

    @AiIdempotent
//    @SaCheckPermission("dict:del")
    @GetMapping("del")
    public R del() {
        return sysDictService.del(getInt("id"),get("ids")) ? OK() : ERROR();
    }

    @GetMapping("getAll")
    public R getAll(){
        return OK(sysDictService.getAll());
    }

}

